package ai.people.netmon.telegram.service.impl;

import ai.people.netmon.framework.domain.telegram.entity.Channels;
import ai.people.netmon.telegram.domain.request.channels.ChannelsRequest;
import ai.people.netmon.framework.model.response.PageResponse;
import ai.people.netmon.telegram.mapper.ManageChannelsMapper;
import ai.people.netmon.telegram.service.ManageChannelsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 管理系统-电报服务实现
 *
 * @author yuanqinglong
 * @date 2022/01/06
 */
@Service
public class ManageChannelsServiceImpl implements ManageChannelsService {

    @Autowired
    private ManageChannelsMapper channelsMapper;


    /**
     * 添加群组
     *
     * @param channels 渠道
     * @return int
     */
    @Override
    public int addChannel(Channels channels) {
        return channelsMapper.insert(channels);
    }

    /**
     * 更新群组
     *
     * @param channels 渠道
     * @return int
     */
    @Override
    public int updateChannel(Channels channels) {
        return channelsMapper.updateById(channels);
    }

    /**
     * 通过id查询
     *
     * @param id id
     * @return {@link Channels}
     */
    @Override
    public Channels selectById(Long id) {
        return channelsMapper.selectById(id);
    }


    /**
     * 分页查询群组
     *
     * @param channelsConditions 查询条件
     * @return {@link PageResponse}<{@link Channels}>
     */
    @Override
    public PageResponse<Channels> selectChannelsPage(ChannelsRequest channelsConditions) {
        Page<Channels> channelsPage = new Page<>(channelsConditions.getPageNo(), channelsConditions.getPageSize());
        LambdaQueryWrapper<Channels> conditions = channelsConditions.createConditions();
        Page<Channels> selectPage = channelsMapper.selectPage(channelsPage, conditions);
        return PageResponse.builder(selectPage.getRecords(), selectPage.getTotal());
    }

    /**
     * 退群
     *
     * @param id 群id
     * @return int
     */
    @Override
    public int exitChannels(Long id) {
        // TODO: 2022/1/7 调用其他服务退出接口

        return 0;
    }
}
